﻿Public Class DRUGGROUP
    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub DRUGGROUP_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SelectDatagridMASGRPDRG()

        DesignForm(Me)
        DesignGrid(MASGRPDRGGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridMASGRPDRG()
        Dim objSelectDatamasclsxray As New masgrpdrg
        Dim MASGRPDRG As DataTable
        MASGRPDRG = connect.GetTable(objSelectDatamasclsxray.selectMasgrpdrg_)
        MASGRPDRGGrid.PrimaryGrid.DataSource = MASGRPDRG
    End Sub

    Private Sub MASGRPDRGGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASGRPDRGGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสกลุ่มยา").Value() IsNot DBNull.Value Then
            GDCODETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสกลุ่มยา").Value()
        Else
            GDCODETxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อกลุ่มยา").Value() IsNot DBNull.Value Then
            GRPDRGTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อกลุ่มยา").Value()
        Else
            GRPDRGTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            masgrpdrgStatusChk.Checked = True
        Else
            masgrpdrgStatusChk.Checked = False
        End If
        connect = CONDB.NewConnection()
        If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
            Try
                Dim Sql As String
                connect.BeginTrans()
                Sql = "UPDATE masgrpdrg SET "
                If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
                    Sql += "`status` = 1 "
                Else
                    Sql += "`status` = 0 "
                End If
                Sql += "WHERE `gdcode` = '" & GDCODETxt.Text & "' ;"

                connect.ExecuteNonQuery(Sql)
                connect.CommitTrans()
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            End Try
        End If
        connect.Dispose()
        addMasgrpdrg.Enabled = False
    End Sub

    Private Sub addMasgrpdrg_Click(sender As Object, e As EventArgs) Handles addMasgrpdrg.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If GRPDRGTxt.Text.ToString.Length > 0 Then
                    Dim objInsertData As New masgrpdrg
                    objInsertData.GRPDRG_ = GRPDRGTxt.Text
                    objInsertData.STATUS_ = masgrpdrgStatusChk.Checked
                    objInsertData.insertMasgrpdrgData()

                    SelectDatagridMASGRPDRG()

                    GDCODETxt.Text = ""
                    GRPDRGTxt.Text = ""
                    masgrpdrgStatusChk.Checked = False
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMasgrpdrg_Click(sender As Object, e As EventArgs) Handles editMasgrpdrg.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If GRPDRGTxt.Text.ToString.Length > 0 And GDCODETxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลกลุ่มยาดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New masgrpdrg
                        objEditData.GDCODE_ = GDCODETxt.Text
                        objEditData.GRPDRG_ = GRPDRGTxt.Text
                        objEditData.STATUS_ = masgrpdrgStatusChk.Checked
                        objEditData.editMasgrpdrgData()

                        SelectDatagridMASGRPDRG()

                        GDCODETxt.Text = ""
                        GRPDRGTxt.Text = ""
                        masgrpdrgStatusChk.Checked = False
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
                addMasgrpdrg.Enabled = True
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("masgrpdrg")
        nextform.ShowDialog()
    End Sub

    Private Sub ButtonItem1_Click(sender As Object, e As EventArgs) Handles ButtonItem1.Click
        Dim nextform As New IMPORTEXCEL("masgrpdrg")
        nextform.ShowDialog()
    End Sub
End Class